#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -e /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -e /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat << EODAL > rsp_g_rohf_dir.dal
**DALTON INPUT
.RUN RESPONSE
.DIRECT
**INTEGRAL
.ANGMOM
.SPIN-ORBIT
**WAVE FUNCTIONS
.HF
*SCF INPUT
.THRESHOLD
1e-12
**RESPONSE
*ESR
#.PRINT
# 200
.G-TENSOR
.OZSO1
.OZSO2
.ADD-SO
#.ECC
**END OF DALTON INPUT

EODAL
cat << EOMOL > rsp_g_rohf_dir.mol
ATOMBASIS
STO-3G
------
    2   1 Z
        6.    1 Basis=STO-3G
C1      0.0006122714    0.0000000000    0.0000000000   
        1.    2 Basis=STO-3G
H1      1.5162556382   -1.3708721537    0.0000000000
H2     -0.7584339548    0.6854360769    1.7695110698

EOMOL
cat << 'EOCHK' > rsp_g_rohf_dir.check
log=$1
GREP=egrep

# ?
CRIT1=`$GREP "Final HF energy\: * \-39\.0720838332[01]" $log | wc -l`
TEST[1]=`expr	$CRIT1`
CTRL[1]=1
ERROR[1]="ENERGY NOT CORRECT"

# ?
CRIT1=`$GREP "\@G * xx * yy * zz * xy * yx" $log | wc -l`
CRIT2=`$GREP "\@G OZ\-SO * 141\. * 124\. * 218\. * \-86\. * \-86\." $log | wc -l`
CRIT3=`$GREP "\@G Total * 141\. * 124\. * 218\. * \-86\. * \-86\." $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[2]=3
ERROR[2]="G-TENSOR NOT CORRECT"
str="1 2"
PASSED=1
for i in $str
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi
EOCHK
